#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QListWidgetItem>
#include <QMap>
#include <QPair>
#include <QCloseEvent>
#include <QThread>
#include "privatechat.h"
#include "groupchat.h"
#include "../MeetingServer/messagepackage.h"

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
protected:
    virtual void closeEvent(QCloseEvent *event) override;
private slots:
    void closeThis();
    void on_btn_link_clicked();
    void on_btn_register_clicked();
    void on_btn_login_clicked();
    void onRegState(bool ret);
    void onLoginState(int value);
    void onOnlineUsers(QStringList users);

    void on_lw_onlineUsers_itemDoubleClicked(QListWidgetItem *item);
    void onPrivateChatSendInfo(QString sender, QString receiver, QString info, QString time);
    void onPrivateChat(messagePackage pack);
    void onChatClose(QString receiver);

    void on_btn_createGroup_clicked();
    void onGroup(QStringList, QString);
    void onCreateGroupState(messagePackage);
    void on_lw_group_itemDoubleClicked(QListWidgetItem *item);
    void onGroupChatSendInfo(QString sender, QString groupName, QString info, QString time);
    void onGroupChatClose(QString groupName);
    void onGroupChat(messagePackage pack);
    void onInviteGroup(QString name, QString groupName);
    void onAddGroup(QString groupName);

    void on_btn_upload_clicked();
    void onUpload(bool ret);

    void on_btn_download_clicked();
    void onDownload(QString file);
    void onDownLoadFile(messagePackage pack);
    void onGroupFile(messagePackage pack);

    void on_btn_createMeeting_clicked();
    void onMeeting(QStringList, QString);
    void onRetMeeting(messagePackage pack);
    void onInviteMeeting(messagePackage pack);
    void onCloseMeeting();
    void onClearMeeting();

private:
    Ui::Widget *ui;
    bool flag = false;
    QString userName = nullptr;
    QMap<QString, QPair<PrivateChat*, bool>> chatObj;
    QMap<QString, QPair<GroupChat*, bool>> groupObj;
    bool isMeeting = false;
signals:
    void quitWidget();
    void newInfo(messagePackage pack);
    void newGroupInfo(messagePackage pack);
};
#endif // WIDGET_H
